<template>
  <div class="about">
    <h1>手写promise</h1>
  </div>
</template>
<script setup lang="ts">
import myPromise from './myPromise'

const p1 = new myPromise((resolve, reject) => {
  resolve(100)
  //   reject("错误")
})

// p1.then(res => {
//   console.log(res, 'res')
//   throw new Error('踩踩踩踩踩')
// })?.catch(err => {
//   console.log(err,'err')
// })

const p11 = p1.then(data1 => {
  console.log(data1, 'data1')
  return data1 + 1
})
const p12 = p11?.then(data2 => {
  console.log(data2, 'data2')
  return data2 + 2
})

const p2 = myPromise.resolve(200)
const p3 = myPromise.reject('cuowu')
const p4 = myPromise.all([p1, p2]) //传入promise数组，等待所有都fulfilled,返回结果
p4.then(res => {
  console.log(res, '5555555')
})

const p5 = myPromise.rece([p1, p2]) //传入promise数组，只有一个fulfilled，即返回结果
p5.then(res => {
  console.log(res, 'p5')
})

// p1.then(
//   value => {},
//   reason => {}
// )
</script>
<style></style>
